#!/bin/bash
# Copyright (C) 2024-2025 KoudaiPC Computer Technologies Co., Ltd.
# script name: yandi-host-gen-udisk-image.sh
# author: david921518@qq.com

qcow2_img_file=kpcos-yandi-1.52-nocloud-amd64-3g.qcow2
raw_img_file=kpcos-yandi-1.52-nocloud-amd64-3g.img
gzip_img_file=${raw_img_file}.gz

if [ ! -f $qcow2_img_file ]; then
  echo "no file $qcow2_img_file , exit now"
  exit 1
fi

rm -f $raw_img_file
rm -f $gzip_img_file

qemu-img convert -O raw -f qcow2 $qcow2_img_file $raw_img_file
gzip $raw_img_file

if [ ! -f $gzip_img_file ]; then
  echo "no file $gzip_img_file , exit now"
  exit 1
fi

exit 0
